package cn.kgc.crowdfundingadmin03.controller;

import cn.kgc.crowdfundingadmin03.common.ResultEntity;
import cn.kgc.crowdfundingadmin03.pojo.Auth;
import cn.kgc.crowdfundingadmin03.service.AuthService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author shkstart
 * @create 2020-03-04 10:17
 */
@Controller
public class AuthController {


    @Resource
    AuthService authService;


    //查询所有
    @ResponseBody
    @RequestMapping("/assign/get/all/auth")
    public ResultEntity<List<Auth>> getAllAuth() {
        List<Auth> allAuth = authService.getAllAuth();
        return ResultEntity.successWithoutData(allAuth);
    }

    //查询authId的回显
    @ResponseBody
    @RequestMapping("/assign/get/assigned/auth/id/list")
    public ResultEntity<List<Integer>> assigngetassigendauthidlist(@RequestParam("roleId") Integer roleId) {
        List<Integer> assignedAuthIdList = authService.getAssignedAuthIdList(roleId);
        return ResultEntity.successWithoutData(assignedAuthIdList);
    }

    /*    @ResponseBody
        @RequestMapping("/assign/do/assign")
        public ResultEntity<String> doRoleAssignAuth(
                @RequestBody Map<String, List<Integer>> assignDataMap) {
            authService.updateRelationShipBetweenRoleAndAuth(assignDataMap);
            return  ResultEntity.successWithoutData();
        }*/
    @ResponseBody
    @RequestMapping("/assign/do/assign")
    public ResultEntity<String> doRoleAssignAuth(
            @RequestBody Map<String, List<Integer>> assignDataMap) {

        authService.updateRelationShipBetweenRoleAndAuth(assignDataMap);

        return ResultEntity.successWithoutData();
    }

}
